#!/usr/bin/env python3.6
# -*- encoding: utf-8 -*-
'''
@File    :   RPC.py
@Time    :   2020/09/20 04:02:25
@Author  :   Tang Jing 
@Version :   1.0.0
@Contact :   yeihizhi@163.com
@License :   (C)Copyright 2020
@Desc    :   None
'''
from TDhelper.network.http.RPC import RPC
from TDhelper.network.rpc.Client.rpc import client
from core.config import *
from core.log import logging, LOGGING

# 加载RPC列表
REMOTE_SERVICE = None


def LoadRpc(*args,**kwargs):
    try:
        REMOTE_SERVICE = client(
            source_service=cfg.SERVICE_KEY,
            uri=str.split(cfg.RPC_CONFIG_URI)[0],
            path="api/rpcb",
            service_conf={
                "service_key":cfg.SERVICE_KEY,
                "secret":cfg.SERVICE_ACCESS_SECRET
            },
            services=RPC_LOADS
        )
        return True, "Load Rpc success.", REMOTE_SERVICE
    except Exception as e:
        REMOTE_SERVICE = None
        logging.error(e)
        return False, "Load Rpc fail. see more in log file.", None


state, msg, REMOTE_SERVICE = LoadRpc()
if not state:
    raise Exception(msg)
